#include<iostream>
using namespace std;
typedef long long LL;
LL n, m, x, y;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m >> x >> y;
		if (n == m && n == 1) {
			cout << 0 << endl;
			continue;
		}
		if (x == y || y == 2 * x) {
			int k = min(n, m) - 1;
			cout << y * k + abs(m - n) * x << endl;
			continue;
		}
		if (x < y) {
			LL ma = (n + m - 2) * x;
			cout << ma << endl;
		}
		else {
			
		}
	}
	return 0;
}